<?php
namespace Home\Controller;
use Think\Controller;

class SavedealmsgboardController extends  BaseController
{
	public function index(){
		
		$root = get_baseroot();
		
		$user =  $GLOBALS['user_info'];
		$root['session_id'] = \es_session::id();
		$user_id  = intval($user['id']);
		if ($user_id >0){
			$is_ajax = intval($GLOBALS['request']['is_ajax']);

	    	$verify_code = strim($GLOBALS['request']['verify_code']);
			
			$data = array();
			$data["user_name"] = strim($GLOBALS['request']["user_name"]);
			$data["ID_NO"] = strim($GLOBALS['request']["ID_NO"]);
			$data["mobile"] = strim($GLOBALS['request']["mobile"]);
			$data["money"] = floatval($GLOBALS['request']["money"]);
			$data["time_limit"] = strim($GLOBALS['request']["time_limit"]);
			$data["usefulness"] = $GLOBALS["db"]->getOne("select name from ".DB_PREFIX."deal_loan_type where id = ".intval($GLOBALS['request']["usefulness"]));
			
			$data["create_time"] = to_date(TIME_UTC);
			$data["status"] = 0;
			$data["unit"] = intval($GLOBALS['request']["unit"]);
			
			if($verify_code==""){
				$root['show_err'] ="请输入手机验证码";
				output($root);
			}
			//判断验证码是否正确
			if($GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."mobile_verify_code WHERE mobile='".strim($data['mobile'])."' AND verify_code='".strim($verify_code)."' AND create_time + ".SMS_EXPIRESPAN." > ".TIME_UTC." ")==0){
				$root['show_err'] ="手机验证码出错,或已过期";
				output($root);	
			}		
			
			if($data["user_name"]=="")
			{
				$root['show_err'] ="请填写您的真实姓名";
				output($root);
			}
			if($data["ID_NO"]=="")
			{
				$root['show_err'] ="请填写您的身份证号码";
				output($root);
			}
			if($data["mobile"]=="")
			{
				$root['show_err'] ="请填写您的手机号";
				output($root);
			}
			if($data["money"] <= 0)
			{
				$root['show_err'] ="请填写贷款金额";
				output($root);
			}
			if($data["time_limit"]=="")
			{
				$root['show_err'] ="请填写贷款期限";
				output($root);
			}
			
			$GLOBALS['db']->autoExecute(DB_PREFIX."deal_msgboard",$data,'INSERT','','SILENT');
			$id = $GLOBALS['db']->insert_id();
			if($id){
				$root['response_code'] = 1;
				$root['show_err'] ="提交成功,等待管理员审核";
			}else{
				$root['show_err'] ="提交失败！";
			}
			
			
			
		}else{
			$root['response_code'] = 0;
			$root['show_err'] ="未登录";
			$root['user_login_status'] = 0;
		}
		$root['program_title'] = "登记借款";
		output($root);		
	}
	
}
?>
